1
//--------------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //--------------------------------------------------------------------------
11 namespace Microsoft
.ParallelComputingPlatform
.ParallelExtensions
.Samples
13 class Sphere
: SceneObject
18 public Sphere(Vector center
, double radius
, Surface surface
) : base(surface
) { Center = center; Radius = radius; }
20 public override ISect
Intersect(Ray ray
)
22 Vector eo
= Vector
.Minus(Center
, ray
.Start
);
23 double v
= Vector
.Dot(eo
, ray
.Dir
);
31 double disc
= Math
.Pow(Radius
, 2) - (Vector
.Dot(eo
, eo
) - Math
.Pow(v
, 2));
32 dist
= disc
< 0 ? 0 : v
- Math
.Sqrt(disc
);
34 if (dist
== 0) return ISect
.Null
;
35 return new ISect(this, ray
, dist
);
38 public override Vector
Normal(Vector pos
)
40 return Vector
.Norm(Vector
.Minus(pos
, Center
));